#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<wait.h>
#include<signal.h>
#include<stdlib.h>

int main()
{
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fork fail");
        return 1;
    }

    if(pid == 0)
    {
        //子进程
        while(1)
        {
            printf("I am a child process\n");
            sleep(1);
            abort();
        }
    }
    if(pid >0)
    {
        //父进程
        int status;
        pid_t child_pid = waitpid(pid,&status,0);
        if (WIFEXITED(status)) 
        {
            //子进程正常退出
            int exit_code = WEXITSTATUS(status);
            printf("子进程退出码：%d\n", exit_code);
        }
        else if (WIFSIGNALED(status)) 
        {
            // 子进程被信号终止
             int signal_number = WTERMSIG(status);
             printf("子进程被信号终止：%d\n", signal_number);
        }
    }
    
    return 0;
}